//
// Created by tang on 22-10-25.
//

#ifndef LEARNOPENGL_INTERPOLATION_HPP
#define LEARNOPENGL_INTERPOLATION_HPP

#include "app/base_app.hpp"
#include "gl/gl_utils.hpp"
#include "input/drag_helper.hpp"
#include <list>

class InterpolationApp final: public App
{
public:
    InterpolationApp(GLFWwindow *win, const char* name);
    ~InterpolationApp();

    void OnInitialize() override;
    void OnCleanup() override;

protected:
    void RenderConfigUI() override;
    void RenderFrame(double delta_time, double total_time) override;

    void OnWindowResized(int w, int h) override;
    void OnMouseClicked(int button, int mods, bool is_press) override;
    void OnMouseMove(double x, double y) override;

private:
    void FitDataRange();

    void DrawDataEditor();

private:
    GL::ProgramPtr m_interpolation_;
    GL::ProgramPtr m_wave_;
    GL::VertexArrayPtr m_vao1_;
    GL::VertexArrayPtr m_vao2_;

    std::vector<std::pair<GLfloat, GLfloat>> m_points_;
    std::vector<GLfloat> m_interpolation_data_;
    bool m_data_changed_;
    int  m_interpolation_algorithm_;
    glm::vec4 m_axis_ranges_;

    DragHelper m_drag_;
};

#endif//LEARNOPENGL_INTERPOLATION_HPP
